package com.ghsc.ghxc.jsb.service

import android.text.TextUtils
import com.alivc.auicommon.common.roombase.Const
import com.aliyun.auiappserver.AppServerTokenManager
import com.cn.appcore.event.RxBus
import com.cn.appcore.event.RxBusBean
import com.cn.appcore.ext.loge
import com.cn.appcore.utils.GsonUtil
import com.ghsc.ghxc.jsb.config.CustSignKey
import com.ghsc.ghxc.jsb.ui.live.bean.CustObserverDataBean
import com.ghsc.ghxc.jsb.ui.live.bean.CustObserverLiveDataBean
import com.ghsc.ghxc.jsb.ui.live.bean.CustObserverNotDataBean
import com.ghsc.ghxc.jsb.ui.message.view.CustMsgType
import com.google.gson.Gson
import com.netease.nimlib.sdk.Observer
import com.netease.nimlib.sdk.msg.model.CustomNotification

/**
 * 项目：GuoHuaMall
 * 包名：com.ghsc.ghxc.service
 * 类名：MyCustObserveCustomNotification
 * 创建时间：2023/10/26 23:09
 * 创建人 @author： xiaolin
 * 描述 ：Todo... 监听监听自定义系统通知接收回调。
 */
class MyCustObserveCustomNotification : Observer<CustomNotification> {
    override fun onEvent(t: CustomNotification?) {
        loge("监听云信Im的自定义系统通知content="+t!!.content)
        if (t == null || TextUtils.isEmpty(t.content)) return


        if ( !TextUtils.isEmpty(AppServerTokenManager.getAppServerToken()) && !TextUtils.isEmpty(
                Const.getUserId())) {
            val msgBean  = GsonUtil.GsonToJsonClass(t.content, CustObserverDataBean::class.java)
            when(msgBean.type){
                CustMsgType.CUST_IM_LIVE_ORDER ->{
                    //直播间下单
//                    val msgBean  = GsonUtil.GsonToJsonClass(t.content, CustObserverNotDataBean::class.java)
//                    if (!TextUtils.isEmpty(msgBean.data.msg)){
//                        RxBus.getDefault().post(RxBusBean(CustSignKey.CHAT_LIVE_ORDER, CustSignKey.CHAT_LIVE_ORDER,msgBean.data.msg))
//                    }
                }
                CustMsgType.CUST_IM_LIVE_BLACK_ADD ->{
                    //直播间黑名单添加
//                    val msgBean  = GsonUtil.GsonToJsonClass(t.content, CustObserverNotDataBean::class.java)
//                    if (msgBean.data.list.isNotEmpty()){
//                        for (i in msgBean.data.list.indices)
//                            LiveBlackList.liveBlackSetList.add(msgBean.data.list[i].toString())
//                        RxBus.getDefault().post(RxBusBean(CustSignKey.CHAT_LIVE_ADD, CustSignKey.CHAT_LIVE_ADD,Gson().toJson(msgBean.data.list)))
//                    }
                }
                CustMsgType.CUST_IM_LIVE_BLACK_DEL ->{
                    //直播间黑名单移除
//                    val msgBean  = GsonUtil.GsonToJsonClass(t.content, CustObserverNotDataBean::class.java)
//                    if (msgBean.data.list.isNotEmpty()){
//                        for (i in msgBean.data.list.indices)
//                            LiveBlackList.liveBlackSetList.remove(msgBean.data.list[i])
//                        RxBus.getDefault().post(RxBusBean(CustSignKey.CHAT_LIVE_DEL, CustSignKey.CHAT_LIVE_DEL,Gson().toJson(msgBean.data.list)))
//                    }
                }
                CustMsgType.CUST_IM_LIVE_SENDMSG ->{
                    //直播间虚假发送信息。
                    val msgBean  = GsonUtil.GsonToJsonClass(t.content, CustObserverLiveDataBean::class.java)
                    if (msgBean.data.list.isNotEmpty()){
                        RxBus.getDefault().post(RxBusBean(CustSignKey.IM_LIVE_SEND_MSGS, CustSignKey.IM_LIVE_SEND_MSGS,msgBean))
                    }
                }
                CustMsgType.CUST_IM_LIVE_COUNT ->{
                    //直播 人数倍数。
                    val msgBean  = GsonUtil.GsonToJsonClass(t.content, CustObserverNotDataBean::class.java)
                    RxBus.getDefault().post(RxBusBean(CustSignKey.IM_LIVE_REN_COUNT, CustSignKey.IM_LIVE_REN_COUNT,msgBean.data.num_multiple))
                }

            }
        }
    }
}